//logs.js
const app = getApp()
var module=require("../../../utils/jinbo/caigoulianmeng.js");
var url=app.globalData.url;
Page({
  data: {
    page:0,
    companies:null,
  	language:'',
    imageUrl:app.globalData.imageUrl,
    inputShowed: false,
    inputVal: "",
    typeId:0,
    tabId: 0,
    type: null,
    scrollWidth:0,
    number:0,
  },
  onLoad: function() {
    var that= this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollWidth: res.windowWidth,
          language:app.globalData.lang,
          imageUrl:app.globalData.imageUrl,
        });       
      }
    });
    this.changeCompanies(true);
  },
  appendCompanies:function(){
    this.changeCompanies(false);
  },
  changeCompanies:function(isRefresh){
    const that = this;
    wx.showLoading({
      title:'正在加载...'
    });
    wx.request({
      url:url+'ciie/buyer/showList',
      header:{'content-type': 'application/json',},
      method:'POST',
      data:{
        type:this.data.typeId,
        title:this.data.inputVal,
        language:this.data.language,
        page:isRefresh?0:this.data.page+1,
            },
      success: function(res) {
      console.log(res);
      if(res.data.code==1){
        if(isRefresh){
          var companies=res.data.data.companies;
          var page=0;
        }else{
          var companies=that.data.companies;
          var page=that.data.page+1;
          for(var i=0;i<res.data.data.companies.length;i++){
          companies.push(res.data.data.companies[i]);
          }
        }
        that.setData({
          companies:companies,
          type:res.data.data.type,
          page:page,
        },function(){
          wx.hideLoading();
        });
      }else if(res.data.code==0){
          wx.showToast({
            title:res.data.msg,
            icon:"none"
          });
      }
      }  
    });
  },
  checkDetail:function(e){
    wx.navigateTo({
      url:'/pages/jinbo/caigoulianmengxiangqing/index?id='+e.currentTarget.dataset.id
    });
  },
  clearInput: function() {
    this.setData({
      inputVal: ""
    });
    this.changeCompanies(true);
  },
  inputTyping: function(e) {
    this.setData({
      inputVal: e.detail.value
    });
    this.changeCompanies(true);
  },
  selectedTap: function(e) {
    this.setData({
        typeId:e.currentTarget.dataset.id,
        tabId:e.currentTarget.dataset.index,
        number:0,
      });
    this.changeCompanies(true);
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: app.globalData.shareTitle,
      path: app.globalData.sharePath,
      imageUrl: '../../../images/share_img.png',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
})